CREATE TABLE math_task (
    id serial PRIMARY KEY,
    "text" text,
    tags varchar[],
    photo_ids varchar[],
    solution_photo_ids varchar[],
    theme_id integer REFERENCES theme,
    source_id integer REFERENCES source,
    number_in_kim_id integer REFERENCES number_in_kim
);

INSERT INTO theme (name, subject_id) VALUES
('Решение уравнений', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Теория вероятности', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Планиметрия', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Вычислительные выражения', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Стереометрия', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Производные на графике', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Формулы', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Текстовые задачи', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Функции', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Производные', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Логарифмические неравенства', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Показательные неравенства', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Алгебраические неравенства', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Экономические задачи', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Параметры', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Логические задачи', (SELECT id FROM subject WHERE sysname = 'MATH'));

INSERT INTO number_in_kim (name, subject_id) VALUES
('1', (SELECT id FROM subject WHERE sysname = 'MATH')),
('2', (SELECT id FROM subject WHERE sysname = 'MATH')),
('3', (SELECT id FROM subject WHERE sysname = 'MATH')),
('4', (SELECT id FROM subject WHERE sysname = 'MATH')),
('5', (SELECT id FROM subject WHERE sysname = 'MATH')),
('6', (SELECT id FROM subject WHERE sysname = 'MATH')),
('7', (SELECT id FROM subject WHERE sysname = 'MATH')),
('8', (SELECT id FROM subject WHERE sysname = 'MATH')),
('9', (SELECT id FROM subject WHERE sysname = 'MATH')),
('10', (SELECT id FROM subject WHERE sysname = 'MATH')),
('11', (SELECT id FROM subject WHERE sysname = 'MATH')),
('12', (SELECT id FROM subject WHERE sysname = 'MATH')),
('13', (SELECT id FROM subject WHERE sysname = 'MATH')),
('14', (SELECT id FROM subject WHERE sysname = 'MATH')),
('15', (SELECT id FROM subject WHERE sysname = 'MATH')),
('16', (SELECT id FROM subject WHERE sysname = 'MATH')),
('17', (SELECT id FROM subject WHERE sysname = 'MATH')),
('18', (SELECT id FROM subject WHERE sysname = 'MATH'));

INSERT INTO source (name, subject_id) VALUES
('Сборник задач по математике', (SELECT id FROM subject WHERE sysname = 'MATH')),
('Сайт 2', (SELECT id FROM subject WHERE sysname = 'MATH'));